import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class PageStatePage extends StatelessWidget {
  PageStatePage({
    super.key,
    required this.child,
  });
  final Widget child;
  final controller = Get.put(PageStateController());
  final state = Get.find<PageStateController>().state;

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      switch (state.state.value) {
        case PageLoadState.loading:
          return LoadingView();
        case PageLoadState.empty:
          return EmptyView(
            title: '点击刷新',
            onTap: controller.onRetry,
          );
        default:
          return child;
      }
    });
  }
}
